#!/usr/bin/env bash

set -x
set -e

MONGO_ADDR=192.168.1.88:27002
MONGO_DB=app_data
USERNAME=work
PASSWORD='n%y$YuL*nVFZ0KSP'

SDB_ADDR=192.168.1.153:11810

# mongodb 数据导出程序
MONGO_EXPORT=`pwd`/bin/linux/mongoexport

# SDB数据导入程序
SDB_IMPORT=/opt/sequoiadb/bin/sdbimprt

mkdir -p ~/app_data

# 获得CPU数目
cpu_num=`cat /proc/cpuinfo |grep "processor"|wc -l`

TARGET_DIR=~/app_data
rm -rf ${TARGET_DIR}/*

for item in acquirer_event annual_reports baidu_news bid_detail bulletin company_data company_information company_information_pedata court_ktgg enterprise_data_gov enterprise_owing_tax ershoufang_anjuke ershoufang_fangdd ershoufang_lianjia exchange_rate exit_event financing_events financing_events_innotree investment_events investment_funds investment_institutions investment_institutions_innotree judge_process judgement_wenshu land_auction land_auction_fang land_project_selling land_selling_auction listing_events loupan_anjuke loupan_fangdd loupan_lianjia neighborhood_anjuke net_loan_blacklist news nssgs_info patent penalty ppp_project shixin_info ssgs_baseinfo ssgs_caibao_assets_liabilities ssgs_caibao_cash_flow ssgs_caibao_companies_ability ssgs_caibao_profit ssgs_notice_cninfo ssgs_regular_report ssgs_rules tax_payer_level_A top_ten_shareholder xiaoqu_fangdd xiaoqu_lianjia zhixing_info enterprise_data_gov_change_info industry_news exchange_rate
do
   ${MONGO_EXPORT} -h ${MONGO_ADDR} -d ${MONGO_DB} -c ${item} --query "{\"_utime\":{\$gte: \"2018-05-26 03:00:00\"}}" -u ${USERNAME} -p ${PASSWORD} -o "${TARGET_DIR}/${item}.json"
   ${SDB_IMPORT} --hosts=${SDB_ADDR} --type=json -c ${MONGO_DB} -l ${item} --file "${TARGET_DIR}/${item}.json" -v -j ${cpu_num} -n 1000
   echo "导入完成: ${item}"
done


